<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
	</head>
	<body>
		<div class="app">
            <input type="text" v-model="inpV">
			<button @click="add">add</button>
			
			<ul>
				<li v-for="item in arr" :key="item.id">
					<input type="checkbox">
					{{item.name}}
				</li>
			</ul>
		</div>
		<script>
			new Vue({
				el:".app",
				data:{
					arr:[
						{id:0,name:"小李"},
						{id:1,name:"小王"},
						{id:2,name:"小张"}
					],
					inpV:""
				},
				methods:{
					add(){
						let obj={//创建一个新的对象,id、name
							id:this.arr.length,
							name:this.inpV
						}
						console.log(obj);
						
						this.arr.unshift(obj);//添加对象
						this.inpV="";//添加结束，清空input
					}
				}
			})
		</script>
	</body>
</html>
